/**
 * 
 */
package com.wolfpire.info.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.wolfpire.info.model.SocialSerCountInfo;
import com.wolfpire.info.service.SocialSerCountInfoService;
import com.wolfpire.system.common.AuthorityUtils;
import com.wolfpire.system.common.EasyuiPage;
import com.wolfpire.system.common.EasyuiPagination;
import com.wolfpire.system.common.Page;
import com.wolfpire.system.common.Result;
import com.wolfpire.system.common.springmvc.PrincipalArgument;
import com.wolfpire.system.model.Authority;
import com.wolfpire.system.model.User;

/**
 * 社会服务统计 控制器
 * @author lihd
 *
 */

@Controller
@RequestMapping("/socialSerCountInfo")
public class SocialSerCountInfoController {
	
	@Resource private SocialSerCountInfoService socialSerCountInfoService;
	
	@RequestMapping("/list")
	public ModelAndView list(@PrincipalArgument User user, @RequestParam Long menuId) {
		List<Authority> operAuthorities = AuthorityUtils.getAperAuthorities(user, menuId);
		return new ModelAndView("info/socialSerCountInfo/socialSerCountInfo_list", "operAuthorities", operAuthorities);
	}
	
	@ResponseBody
	@RequestMapping("/queryList")
	public EasyuiPagination<SocialSerCountInfo> queryList(EasyuiPage<SocialSerCountInfo> page, SocialSerCountInfo filtersocialSerCountInfo) {
		Page<SocialSerCountInfo> socialSerCountInfos = this.socialSerCountInfoService.setPageDataList(page, filtersocialSerCountInfo);
		return new EasyuiPagination<SocialSerCountInfo>(socialSerCountInfos);
	}
	
	@RequestMapping(value = "/add")
	public ModelAndView add(HttpSession session, SocialSerCountInfo socialSerCountInfo) {
		ModelAndView mv = new ModelAndView("info/socialSerCountInfo/socialSerCountInfo_add");
		mv.getModelMap().addAttribute(socialSerCountInfo);
		return mv;
	}
	
	@ResponseBody
	@RequestMapping("/save")
	public Result save(@PrincipalArgument User user, SocialSerCountInfo socialSerCountInfo) {
		try {
			socialSerCountInfo.setCreateUserId(user.getId());
			socialSerCountInfo.setCreateUserName(user.getNickName());
			this.socialSerCountInfoService.saveOrUpdate(socialSerCountInfo);
			return Result.SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return Result.FAILURE;
		}
	}
	
	@RequestMapping("/edit")
	public ModelAndView edit(Long id) {
		ModelAndView mv = new ModelAndView("info/socialSerCountInfo/socialSerCountInfo_add");
		if (null != id) {
			SocialSerCountInfo socialSerCountInfo = this.socialSerCountInfoService.get(id);
			mv.addObject(socialSerCountInfo);
		}
		return mv;
	}
	
	@RequestMapping("/detail")
	public ModelAndView detail(@RequestParam(value = "id", required = true) Long id) {
		ModelAndView mv = new ModelAndView("info/socialSerCountInfo/socialSerCountInfo_detail");
		try {
			if (null != id) {
				SocialSerCountInfo socialSerCountInfo = this.socialSerCountInfoService.get(id);
				mv.addObject(socialSerCountInfo);
			}
			return mv;
		} catch (Exception e) {
			e.printStackTrace();
			return new ModelAndView("/proms/common/error");
		}
	}
	
	@ResponseBody
	@RequestMapping("/delete")
	public Result delete(@RequestParam(value="id") Long id) {
		try {
			this.socialSerCountInfoService.del(id);
			return Result.SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return Result.FAILURE;
		}
	}
}
